(function ($) {
    /*模板引擎设置*/
    _.templateSettings = {
        interpolate: /\{\{(.+?)\}\}/g
    };


    $.log = function (content, title, format) {
        if (typeof content == 'object') {
            content = JSON.stringify(content, null, '\t');
            if (format) {
                content = content.replace(/\n/g, '<br/>').replace(/\t/g, ' &nbsp; &nbsp; ');
            }
            if (arguments.length > 3) {
                var keywords = Array.prototype.slice.call(arguments, 3);
                for (var i = 0; i < keywords.length; i++) {
                    var keyword = keywords[i];
                    content = content.replace(new RegExp('"' + keyword + '"', "g"), '<span style="background:yellow">"' + keyword + '"</span>');
                }
            }
        }

        // 为消息增加点击事件，开始时折叠消息
        var $msg = $('<p/>').addClass('shortMsg').click(function () {
            $(this).toggleClass('shortMsg');
        });


        var _title = title || ">>";
        $('<span/>').css('color', 'red').text(_title + ' ').appendTo($msg);
        $('<span/>').html(content).appendTo($msg);
        $msg.appendTo('#debugInfo > div');
    };

    $("#reloadPage").on("click", function () {
        location.reload();
    });

})(Zepto);

(function ($) {
    $(document).ready(function () {
        var $divShow=$("#divShow");
        var TestRouter=Backbone.Router.extend({
            routes:{
                'search2/:key':'search2_key',
                'search3/:key':'search3_key'
            },

            search2_key:function(key){
                $divShow.html("search2:"+key);
            },

            search3_key:function(key){
                $divShow.html("search3:"+key);
            }

        });

        var router=new TestRouter();
        var intNum=0;

        setInterval(function(){
            intNum++;
            if(intNum%2==0){
                router.navigate("search2/abc",{trigger:true});
            }else{
                router.navigate("search2/def",{trigger:true});
            }
        },3000);

        Backbone.history.start();

        $("#testBtn").on("click",function(){
            if($(this).val()=="stop"){
                $(this).val("start");
                Backbone.history.stop();
            }else{
                $(this).val("stop");
                Backbone.history.start();
            }
        });

    });
})(Zepto);